package written.test;

import javafx.util.Pair;

import java.util.*;
import java.util.concurrent.DelayQueue;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/18  16:02
 * @Description:
 */
public class Wangyi1 {
    public static void main(String[] args) {
        Wangyi1 wangyi1 = new Wangyi1();
//        System.out.println(wangyi1.getMatchBracketsNum("[({}[])]",8));
        long[][] logs = {{1610000000000L,1620000000000L}, {1610000000000L,1610000001000L}, {1615000000000L,1620000000000L}};
        long[] tss = {1610000002000L,1616000000000L,1630000000000L};

        int[][] res = wangyi1.search_log(logs, tss);
        for(int[] a: res){
            System.out.println(Arrays.toString(a));
        }
    }
    public int[][] search_log2 (long[][] logs, long[] tss) {
        // write code here
       return null;
    }
    public int[][] search_log (long[][] logs, long[] tss) {
        // write code here
        List<Integer>[] cache = new List[tss.length];
        for(int i = 0; i < logs.length; i++){
            long start = logs[i][0];
            long end = logs[i][1];
            for(int j = 0; j < tss.length; j++){
                if(tss[j] >= start && tss[j] <= end){
                    if(cache[j]==null){
                        cache[j] = new ArrayList<Integer>();
                    }
                    cache[j].add(i);
                }
            }
        }
        int[][] res = new int[tss.length][];
        for(int i = 0; i < tss.length; i++){
            if(cache[i] == null) {
                res[i] = new int[]{};
            }else{
                List<Integer> list = cache[i];
                res[i] = list.stream().mapToInt(Integer::intValue).toArray();
            }
        }
        return res;
    }





    public int getMatchBracketsNum (String inString, int inStringNum) {
        if(inStringNum==0) return 0;
        if((inStringNum&1)==1) return -1;
        Deque<Character> stack = new LinkedList<>();
        int ans = 0;
        for(int i = 0; i < inString.length(); i++){
            char ch = inString.charAt(i);
            if(ch=='[' || ch=='(' || ch == '{') stack.push(ch);
            else{
                if(stack.isEmpty()) return -1;
                switch (ch){
                    case ')':
                        if(stack.peek()!='(') return -1;
                        ans+=1;
                        stack.pop();
                        break;
                    case  ']':
                        if(stack.peek()!='[') return -1;
                        ans+=2;
                        stack.pop();
                        break;
                    case '}':
                        if(stack.peek()!='{') return -1;
                        ans+=3;
                        stack.pop();
                        break;
                    default:
                       return -1;
                }
            }
        }
        if(!stack.isEmpty()) return -1;
        return ans;
    }
}
